source("rglade.R")

# constants used in the program. Can embed as well
year <- 1993;
lo <- 2;
hi <- 3;
qLim <- 25;

g <- new("glade", server="datapath", user="alin");
date <- read(g,date);
lineorder <- read(g,lineorder);
#lf <- filter(lineorder, (lineorder$lo_discount >=.(lo) && lineorder$lo_discount<=.(hi)
#                             && lineorder$lo_quantity<.(qLim)));

# rest: && lineorder.lo_quantity<.(qLim)
jn <- join(lineorder[filter=((lineorder$lo_discount >=.(lo) && lineorder$lo_discount<=.(hi)
                             && lineorder$lo_quantity<.(qLim))) ], lineorder$lo_orderdate,
           date[filter=date$d_year == .(year)], date$d_datekey);

agg <- aggregate( jn, Sum, lineorder$lo_extendedprice*lineorder$lo_discount, revenue );
result <- as.data.frame(agg, revenue=revenue);
show(result);
